package com.abc.robot01.room.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import androidx.room.RoomWarnings
import com.abc.robot01.room.bean.ChatQuestionBean

@Dao
interface ChatQuestionDao {
    /**
     * 添加问题
     * */
    @Insert
    suspend fun addQuestion(chatQuestionBean: ChatQuestionBean): Long

    /**
     * 添加问题
     * */
    @Insert
    suspend fun addQuestion(chatQuestionBean: List<ChatQuestionBean>): List<Long>

    // Update the question and date fields by id
    @Query("UPDATE chat_question SET question = :newQuestion, date = :newDate WHERE id = :id")
    suspend fun updateQuestionAndDateById(id: Int, newQuestion: String, newDate: String)
    /**
     * 查询所有问题
     * */
    @Query("SELECT * FROM chat_question")
    suspend fun queryAllQuestion(): List<ChatQuestionBean>

//    /**
//     * 查询手持自定对话问题
//     * */
//    @Query("SELECT * FROM chat_question WHERE type = 1")
//    fun queryCustomQuestion(): List<ChatQuestionBean>

    /**
     * 查询手持自定对话问题
     * */
    @Query("SELECT * FROM chat_question WHERE cmd_id = :cmdId AND type = 0")
    suspend fun queryCustomQuestionByCmdId(cmdId: String): List<ChatQuestionBean>

    /**
     * 查询手持自定对话问题
     * */
    @Query("SELECT cmd_id FROM chat_question WHERE type = 1 GROUP BY cmd_id")
    fun queryCustomQuestionCmdIdByGroup(): List<String>

    /**
     * 删除问题
     * */
    @Query("DELETE from chat_question where cmd_id = :cmd")
    suspend fun deleteByCmdId(cmd: String): Int

    /**
     * 删除当个问题
     * */
    @Query("DELETE from chat_question where cmd_id = :cmd")
    suspend fun deleteQuestion(cmd: String): Int
    /**
     * 通过问题查询第一条数据
     * */
    @Query("SELECT * FROM chat_question where question = :question limit 1")
    suspend fun queryCmd(question: String): ChatQuestionBean?

    /**
     * 通过问题查询
     * */
    @Query("SELECT * FROM chat_question WHERE question LIKE '%' || :input || '%'")
    suspend fun queryByQuestion(input: String): List<ChatQuestionBean>

////    /**
////     * 查询所有自定义数据
////     * */
////    @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
////    @Query("SELECT * FROM chat_question WHERE type = 1")
////    fun queryTypeCustomAll(): List<ChatQuestionBean>
//
////    /**
////     * 查询第一条数据
////     * */
////    @Query("SELECT * FROM chat_question WHERE :question like '%'||''||question||''||'%' limit 1")
////    fun queryQuestionFirstByBuilder(question: String): ChatQuestionBean?
//    /**
//     * 更具最大cmd查询数据
//     * */
//    @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
//    @Query("SELECT MAX(CAST(cmd_id AS INTEGER)) FROM chat_question")
//    suspend fun qryMaxId(): Int?

}